package com.sskj.lib.util;


public class CoinUtil {
    /**
     * 转化code
     * btc_usdt  ->BTC/USDT
     */
    public static String showName(String code) {
        return code.replace("_", "/").toUpperCase();
    }

    /**
     * 获取左边币种
     * btc_usdt ->BTC
     */
    public static String getLCode(String code){
        return code.replace("_", "/").toUpperCase().split("/")[0];
    }
    /**
     * 获取右边币种
     * btc_usdt ->USDT
     */
    public static String getRCode(String code){
        return code.replace("_", "/").toUpperCase().split("/")[1];
    }
    public static String keepRMB(String rmb) {
        return NumberUtil.keep(rmb,NumberUtil.rmbNumber);
    }

    public static String keepRMB(double rmb) {
        return keepRMB(rmb + "");
    }

    public static String keepUSDT(String coin) {
        return NumberUtil.keep(coin,NumberUtil.usdtNumber );
    }

    public static String keepUSDT(double coin) {
        return keepUSDT(coin + "");
    }
    /**
     * 币种价格
     *
     * @param code
     * @param price
     * @return
     */
    public static String keepCoinPrice(String code, String price) {
        try {
            Double.valueOf(price);
        } catch (Exception e) {
            return price;
        }
        return NumberUtil.keep(price, getPriceKeepNum(code));
    }

    public static String keepCoinMoney(String code, String money) {
        try {
            Double.valueOf(money);
        } catch (Exception e) {
            return money;
        }
        switch (code) {
            case "BTC/USDT":
            case "BCH/USDT":
            case "ETH/USDT":
            case "LTC/USDT":
            case "ZEC/USDT":
            case "DASH/USDT":
                return NumberUtil.keep(money, 8);
            default:
                return NumberUtil.keep(money, 4);

        }
    }


    /**
     * 获取币种价格保留位数
     *
     * @param code
     * @return
     */
    public static int getPriceKeepNum(String code) {
        if (code == null) {
            return 4;
        }
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "BCH/USDT":
            case "BTC/USDT":
            case "ETH/USDT":
            case "LTC/USDT":
            case "ZEC/USDT":
            case "DASH/USDT":
                return 2;
            case "FEC/MYR":
            case "FEC/TWD":
                return 3;
            case "EOS/USDT":
            case "ETC/USDT":
            case "OMG/USDT":
            case "GNT/USDT":
            case "PST/USDT":
            case "ZRX/USDT":
            case "MANA/USDT":
            case "CQTF/USDT":
            case "HT/USDT":
                return 4;
            case "XRP/USDT":
                return 5;
            case "BCH/BTC":
            case "XMR/ETH":
            case "ETH/BTC":
            case "ETC/BTC":
            case "OMG/BTC":
            case "OMG/ETH":
            case "TRX/USDT":
            case "LTC/BTC":
            case "PST/ETH":
                return 6;
            case "XRP/BTC":
            case "TRX/ETH":
            case "EOS/ETH":
            case "EOS/BTC":
            case "ZRX/BTC":
            case "BAT/BTC":
            case "GNT/BTC":
            case "PST/BTC":
            case "MANA/BTC":
                return 8;
            case "ZRX/ETH":
            case "BAT/ETH":
            case "GNT/ETH":
            case "MANA/ETH":
                return 4;
            default:
                return 2;

        }
    }

    /**
     * 获取币种数量保留位数
     *
     * @param code
     * @return
     */
    public static int getNumKeepNum(String code) {
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "HT/USDT":
                return 2;
            case "BTC/USDT":
                return 6;
            case "ETC/USDT":
            case "BCH/USDT":
            case "LTC/USDT":
            case "EOS/USDT":
            case "ETH/USDT":
                return 4;
            case "XRP/USDT":
                return 2;
            default:
                return 4;
        }
    }


    /**
     * @param code
     * @param num
     * @return
     */
    public static String keepCoinNum(String code, String num) {
        try {
            Double.valueOf(num);
        } catch (Exception e) {
            return num;
        }
        return NumberUtil.keep(num, getNumKeepNum(code));
    }

}
